package com.ydgk.jishuzhan.service.impl;

import com.ydgk.jishuzhan.beans.Blog;
import com.ydgk.jishuzhan.beans.BlogCollection;
import com.ydgk.jishuzhan.dao.BlogMapper;
import com.ydgk.jishuzhan.dao.UserMapper;
import com.ydgk.jishuzhan.service.BlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class BlogServiceImpl implements BlogService {

    @Autowired
    private BlogMapper blogMapper;

    @Autowired
    private UserMapper userMapper;

    public List<Blog> findBlogs() {
        List<Blog> blogs = blogMapper.findBlogs();
        List<Blog> blogs1=new ArrayList<>();
        for (Blog blog:blogs){
            blog.getBlogInfo().setUser(userMapper.findUserById(blog.getUserId()));
            blogs1.add(blog);
        }
        return blogs1;

    }


    public int add(Blog blog) {
        return blogMapper.save(blog);
    }


    public Blog findBlog(Integer id) {
        return blogMapper.findBlog(id);
    }

    @Override
    public List<Blog> findBlogsById(Integer id) {
        return blogMapper.findBlogsByUserId(id);
    }

    @Override
    public int findGoods(Integer id) {
        return blogMapper.findGoods(id);
    }

    @Override
    public void goodAdd(Integer userId, Integer blogId) {
        blogMapper.goodAdd(userId,blogId);
    }

    @Override
    public int findGood(Integer userId, Integer blogId) {
        return blogMapper.findGood(userId,blogId);
    }

    @Override
    public int findCollection(Integer userId, Integer blogId) {
        return blogMapper.finCollection(userId,blogId);
    }

    @Override
    public void collectionAdd(Integer userId, Integer blogId) {
        blogMapper.collectAdd(userId,blogId);
    }

    @Override
    public int findCollections(Integer id) {
        return blogMapper.findCollections(id);
    }

    @Override
    public List<BlogCollection> getCollections(Map<String, Object> map) {
        return blogMapper.getCollections(map);
    }

    @Override
    public Integer queryBlogTotal(Map<String, Object> map) {
        return blogMapper.queryBlogTotal(map);
    }

    @Override
    public void deleteBCollection(Integer id) {
        blogMapper.deleteBCollection(id);
    }


}
